
//==============================================================
//初始化表单
//==============================================================
function InitForm(){

}

//==============================================================
//弹出新窗口
//==============================================================
function OpenWin(url,width,height,scrollbars)
{
	//width=480，height=500
	var winLeft = (screen.availWidth - width) / 2;
	var winTop = (screen.availHeight - height) / 3;
	var winWidth = width;
	var winHeight = height;
	window.open(url,"null","height="+winHeight+",width="+winWidth+",left="+winLeft+",top="+winTop+",scrollbars="+scrollbars+"");
}

//==============================================================
//折叠表单区块
//==============================================================
function WrapBlock(strDivId){
    var objImg = event.srcElement;
	var objDiv = document.getElementById(strDivId);
	var objInnerDivs = objDiv.getElementsByTagName("div");
    if (objImg){
        if (objImg.src.toString().indexOf("block_unwrap") != -1){
            objImg.src = "../../style/images/block_wrap.gif";
			for (var i=0; i<objInnerDivs.length; i++){
			    if(objInnerDivs[i].className == "DivTail"){
				    objInnerDivs[i].style.display = "none";
				}
			}
        }else{			
            objImg.src = "../../style/images/block_unwrap.gif";
            for (var i=0; i<objInnerDivs.length; i++){
			    if(objInnerDivs[i].className == "DivTail"){
				    objInnerDivs[i].style.display = "block";
				}
			}
        }
    }
}

//==============================================================
//鼠标在表格行上时高亮显示
//==============================================================
function FocusTableRow(tableId,rowIndex){
	var preBgColor = null;
	var table = document.getElementById(tableId);
	if (table == null){
    	return;
	}
	if (table.rules != null){
	    table.rules = "none";
	}
	var tbody = table.getElementsByTagName("tbody")[0];
	var rows = tbody.getElementsByTagName("tr");
	for (var i=rowIndex; i < rows.length; i++){
		rows[i].onmouseover = function() { preBgColor=this.style.backgroundColor; this.style.backgroundColor='#CFE4FE'; };
		rows[i].onmouseout = function() { this.style.backgroundColor=preBgColor; };
	}
}

//==============================================================
//Tooltip提示
//==============================================================
var oPopup = window.createPopup();
function Tooltip(msg, fg, bg)
{
    if(Tooltip.arguments.length < 1)
    {
        oPopup.hide();
    }
    else
    {
        if(!fg) fg = "#000000";
        if(!bg) bg = "#FFFFE1";
        var content =
        '<table id="tbContainer" border="0" cellspacing="0" cellpadding="0" bgcolor="' + fg + '"><td>' +
        '<table border="0" cellspacing="0" cellpadding="0" bgcolor="' + bg + 
        '"><td align="left" style="font-size:12px;padding-top:2px;padding-bottom:2px;"><font face="宋体" color="' + fg +
        '" font-size: 12px;>&nbsp\;' + msg +
        '&nbsp\;</font></td></table></td></table>';
        oPopup.document.body.innerHTML = content;
        var popupBody = oPopup.document.body;
        popupBody.style.border = "#000000 1px solid";
        var lefter = event.offsetX;
        var topper = event.offsetY;
        oPopup.show(0, 0, 400, 0);
        oPopup.hide();
        var realHeight = oPopup.document.all.tbContainer.scrollHeight + 1;
        var realWidth = oPopup.document.all.tbContainer.scrollWidth + 5;
        if (event.srcElement.tagName=="AREA")
        {
            oPopup.show(lefter+15, topper+15, realWidth, realHeight, document.body);
        }
        else
        {
            oPopup.show(lefter, topper, realWidth, realHeight, event.srcElement);
        }
    }
}
/*import private.js--begin*/
//All the checkbox are checked.
function clickCheckbox(obj, checkboxname) {
	if (document.forms[0][checkboxname] + "" == "undefined") {
		return;
	}
	if (document.forms[0][checkboxname].length + "" != "undefined") {
		for (i = 0; i < document.forms[0][checkboxname].length; i++) {
			if (!document.forms[0][checkboxname][i].disabled) {
				document.forms[0][checkboxname][i].checked = obj.checked;
			}
		}
	}
	document.forms[0][checkboxname].checked = obj.checked;
}
//pop up
function callNewWindow(url, target, width, height) {
	var l = window.screen.width;
	var w = window.screen.height;
	var al = l / 2 - 400;
	var aw = w / 2 - 300;
	var opt = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=atuo,resizable=yes,width=" + width + ",height=" + height + ",top=" + aw + ",left=" + al + "";
	var newwin = window.open(url, target, opt);
	newwin.focus();
}
//is digits
function isAllDigits(argvalue) {
	argvalue = argvalue.toString();
	var validChars = "0123456789";
	var startFrom = 0;
	for (var n = startFrom; n < argvalue.length; n++) {
		if (validChars.indexOf(argvalue.substring(n, n + 1)) == -1) {
			return false;
		}
	}
	return true;
}
//pages
function currentPage(num) {
	document.forms[0].operationType.value = "queryList";
	document.forms[0].currentPage.value = num;
	document.forms[0].submit();
}
//pages
function goPage() {
	var pages = document.forms[0].currentPage.value;
	if (isAllDigits(pages)) {
		currentPage(pages);
	} else {
		alert("\u8bf7\u8f93\u5165\u6570\u5b57\uff01");
		document.forms[0].currentPage.focus();
	}
}
//operationType
function operation(type) {
	document.forms[0].operationType.value = type;
	document.forms[0].submit();
}
/*import private.js--end*/
/*import pageCheck.js--begin*/
//trim
function trim(s) {
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
//
function strlen(str){
	var i;
	var len;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}
//validate form
function validateRequired(form) {
	var isValid = true;
	var focusField = null;
	var i = 0;
	var fields = new Array();
	oRequired = new required();
	for (x in oRequired) {
		var field = form[oRequired[x][0]];
		
		if (field.type == 'text' ||
			field.type == 'textarea' ||
			field.type == 'file' ||
			field.type == 'select-one' ||
			field.type == 'radio' ||
			field.type == 'password') {
			
			var value = '';
			// get field's value
			if (field.type == "select-one") {
				var si = field.selectedIndex;
				if (si >= 0) {
					value = field.options[si].value;
				}
			} else {
				value = field.value;
			}
			
			if (trim(value).length == 0) {
			
				if (i == 0) {
					focusField = field;
				}
				fields[i++] = oRequired[x][1];
				isValid = false;
				if (fields.length > 0) {
				if(!(focusField.readOnly||focusField.disabled)){
						focusField.focus();
				   }
				   alert(fields.join('\n'));
				}
				return isValid;
			}
		}
	}
	return isValid;
}
//validate form min length
function validateMinLength(form) {

	var isValid = true;
	var focusField = null;
	var i = 0;
	var fields = new Array();
	oMinLength = new minlength();
	for (x in oMinLength) {
		var field = form[oMinLength[x][0]];
		if (field.type == 'text' ||
			field.type == 'textarea') {	
			var iMin = parseInt(oMinLength[x][2]("minlength"));
			if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
				if (i == 0) {
					focusField = field;
				}
				fields[i++] = oMinLength[x][1];
				isValid = false;
			}
		}
	}
	if (fields.length > 0) {
	   focusField.focus();
	   alert(fields.join('\n'));
	}
	return isValid;
}
//validate form max length
function validateMaxLength(form) {
	var isValid = true;
	var focusField = null;
	var i = 0;
	var fields = new Array();
	oMaxLength = new maxlength();
	for (x in oMaxLength) {
		var field = form[oMaxLength[x][0]];
		
		if (field.type == 'text' ||
			field.type == 'textarea') {
			
			var iMax = parseInt(oMaxLength[x][2]("maxlength"));
			if (strlen(field.value) > iMax) {
				if (i == 0) {
					focusField = field;
				}
				fields[i++] = oMaxLength[x][1];
				isValid = false;
			}
		}
	}
	if (fields.length > 0) {
	   focusField.focus();
	   alert(fields.join('\n'));
	}
	return isValid;
}
function validateEmail(form) {
	var bValid = true;
	var focusField = null;
	var i = 0;
	var fields = new Array();
	oEmail = new email();
	for (x in oEmail) {
		if ((form[oEmail[x][0]].type == 'text' ||
			 form[oEmail[x][0]].type == 'textarea') &&
			(form[oEmail[x][0]].value.length > 0)) {
			if (!checkEmail(form[oEmail[x][0]].value)) {
				if (i == 0) {
					focusField = form[oEmail[x][0]];
				}
				fields[i++] = oEmail[x][1];
				bValid = false;
			}
		}
	}
	if (fields.length > 0) {
		focusField.focus();
		alert(fields.join('\n'));
	}
	return bValid;
}

/**
 * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
 * http://javascript.internet.com
 */
function checkEmail(emailStr) {
   if (emailStr.length == 0) {
	   return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) {
	   return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) {
	   return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
	   for (var i = 1; i <= 4; i++) {
		  if (IPArray[i] > 255) {
			 return false;
		  }
	   }
	   return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) {
	   return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) ||
	   (domArr[domArr.length-1].length > 3)) {
	   return false;
   }
   if (len < 2) {
	   return false;
   }
   return true;
}



function ajax(){
		var xmlHttp;
		if(window.XMLHttpRequest){ 
			xmlHttp = new XMLHttpRequest();
		}else if(window.ActiveXObject){ 
			try{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){
					alert("");
				}
			}
		}
		if( xmlHttp == null ){
			return ;
		}
		
				this.sendData = function(method,URL,asy,fun) {
			
			if(asy){
				
				xmlHttp.onreadystatechange = function(){	 
					if( xmlHttp.readyState == 4 && xmlHttp.status == 200 ){
							fun(xmlHttp);
					}             
				}
			     if(method == "POST") {
			        xmlHttp.open("POST",URL,true);
					xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");		

			
					xmlHttp.send(null);
				}else{
					xmlHttp.open("GET",url,true);
					xmlHttp.send(null);
				}
				
			}else{
			    xmlHttp.onreadystatechange = function(){	 
					if( xmlHttp.readyState == 4 && xmlHttp.status == 200 ){
							fun(xmlHttp);
					}             
				}
				if(method == "POST"){
					xmlHttp.open("POST",URL,false);
					xmlHttp.setRequestHeader("Content-Type","application/x-www-form-rlencoded");
					xmlHttp.send(null);
				}else{
					xmlHttp.open("GET",url,false);
					xmlHttp.send(null);
				}
				return xmlHttp;
			}   
		}

	}

/*import pageCheck.js--end*/